<template>
	<view class="container">
		<!-- :url="routes['project_list']" -->
		<view class="intro">TaskSaas mobile version</view>
		<text class="intro">详见：</text>
		<view v-if="user_token">
			<!-- 切换到了switchTab形式 -->
			<!-- <navigator :url="routes['project_list']" hover-class="navigator-hover">
				<uni-link type="default">管理中心</uni-link>
			</navigator> -->
			<view>
				<text class="uni-link" @click="toManage">管理中心</text>
			</view>
			<view>
				<text class="uni-link" @click="doLogout">退出登录</text>
			</view>
			<view>
				<text>最近打开的项目:</text>
			</view>
		</view>
		<view v-else>
			<navigator :url="routes['login']" hover-class="navigator-hover">
				<uni-link type="default">登录</uni-link>
			</navigator>
		</view>
		<!-- #ifdef H5 -->
		<view>只在H5编译</view>
		<!-- #endif -->

		<!-- #ifdef APP -->
		<view>只在ios/安卓编译</view>
		<!-- #endif -->

		<!-- #ifdef MP -->
		<view>只在小程序（微信、支付宝、百度）进行编译</view>
		<!-- #endif -->

		<!-- #ifdef MP-WEIXIN -->
		<view>只在微信小程序进行编译</view>
		<!-- #endif -->

		<!-- #ifndef MP -->
		<view>不在小程序全端编译，只在ios/安卓/h5编译</view>
		<!-- #endif -->
	</view>

</template>



<script>
	import {
		apis,
		routes,
		loadReminds
	} from '@/common/paths.js'
	export default {
		data() {
			return {
				user_token: uni.getStorageSync('user_token'),
				routes: routes,
				e_token: null,
				selected: 1,
				totalRemindSize: 1
			}
		},
		methods: {
			toManage() {
				uni.switchTab({
					url: routes['project_list'],
				});
			},
			doLogout() {
				console.log('bf ', uni.getStorageSync('user_token'));
				uni.removeStorageSync('user_token');
				console.log('removed');
				console.log('aft ', uni.getStorageSync('user_token'));
				uni.reLaunch({
					url: routes['index']
				})
			},
			loadReminds() {
				uni.request({
					url: this.backendServer + apis['do_remind'],
					method: 'get',
					// dataType:'application/json',
					data: {
						'user_id': this.user_token
					},
					success: (res) => {
						uni.hideLoading()
						console.log('success res ', res)
						if (res.data.status) {
							console.log('request ok')
							console.log('res.data.results.hints ', res.data.results.hints)
							this.remind_hints = res.data.results.hints
							this.remind_sysinfos = res.data.results.sysinfos
							let totalRemindSize = res.data.results.hint_size + res.data.results.sys_size
							console.log('totalRemindSize ', totalRemindSize)
							if (this.user_token && totalRemindSize) {
								uni.setTabBarBadge({
									index: 3,
									text: totalRemindSize + ''
								})
							}
						} else {
							uni.showToast({
								title: "获取失败，" + res.data.msg,
								icon: 'fail'
							})
							uni.switchTab({
								url: routes['dashboard']
							})
							// this.project_list = []
						}
					},
					fail: (res) => {
						uni.hideLoading()
						console.log('fail res ', res)
						uni.showToast({
							title: "获取失败，请检查网络联接，" + res,
							icon: 'fail'
						})
						uni.switchTab({
							url: routes['dashboard']
						})
						// this.project_list = []
					}
				})
			}

		},
		// #ifdef H5
		// watch: {
		// 	$route: {
		// 		immediate: true,
		// 		handler(newRoute) {
		// 			if (newRoute.matched.length) {
		// 				let path = newRoute.path.split('/')[3]
		// 				for (const item of this.list) {
		// 					if (Array.isArray(item.pages)) {
		// 						for (const page of item.pages) {
		// 							if (page === path || page.url && page.url === newRoute.path) {
		// 								item.open = true
		// 							}
		// 						}
		// 					}
		// 				}
		// 			}
		// 		}
		// 	}
		// },
		// #endif
		onLoad(e) {
			console.log(e)

			// this.loadReminds()
			loadReminds()
			console.log('user_token onLoad', uni.getStorageSync('user_token'));
			console.log('usertoken ', this.user_token)
			console.log('totalRemindSize aft loadReminds', this.totalRemindSize)

		},
		beforeCreate() {
			console.log('user_token beforeCreate', uni.getStorageSync('user_token'));

		}

	}
</script>

<style>
	.container {
		padding: 20px;
		font-size: 14px;
		line-height: 24px;
	}
</style>